package com.asiainfo.main;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import java.util.Scanner;

import com.asiainfo.operationdb.AddData;
import com.asiainfo.operationdb.CheckData;
import com.asiainfo.datamodel.Coach;
import com.asiainfo.datamodel.CourseShedule;
import com.asiainfo.datamodel.SubscribeCourse;
import com.asiainfo.datamodel.User;

public class test {

	/**
	 * 主程序 测试各功能
	 * 
	 * @param args
	 */

	public Connection conn = null;
	public PreparedStatement ps = null;
	public Statement stmt = null;
	public ResultSet rs = null;

	public static void main(String[] args) throws UnsupportedEncodingException {
		Scanner cin = new Scanner(System.in);
		AddData add = new AddData();
		while (cin.hasNext()) {
			String order = cin.next();
			if (order.equals("exit"))
				return;
			if (order.equals("add-member")) {
				String userName = cin.next();
				CheckData checkData = new CheckData();
				int userID = checkData.getID(userName,
						"select * from user_info");
				if (userID != 0) {
					System.out.println("您已经注册过，无需注册！");
				} else {
					User user = new User();
					user.setValue(userName, cin.next(), cin.next());
					add.addMember(user);
				}
			} else if (order.equals("add-card")) {
				String userName = cin.next();
				String cardTab = cin.next();

				if (cardTab.equals("年卡"))
					add.addCard(userName, cardTab, -1);
				else if (cardTab.equals("次卡"))
					add.addCard(userName, cardTab, cin.nextInt());
				else
					System.out.println("输入有误，请重新输入！");
			} else if (order.equals("add-course")) {
				add.addCourse(cin.next());
			} else if (order.equals("add-coach")) {
				Coach coach = new Coach();
				coach.setValue(cin.next(), cin.next(), cin.nextInt(),
						cin.next());
				add.addCoach(coach);
			} else if (order.equals("schedule")) {
				CourseShedule courseShedule = new CourseShedule();
				courseShedule.setValue(cin.next(), cin.next(), cin.next());
				add.addCourseShedule(courseShedule);
			} else if (order.equals("subscribe")) {
				SubscribeCourse subscribeCourse = new SubscribeCourse();
				subscribeCourse.setValue(cin.next(), cin.next());
				add.addSubscribeCourse(subscribeCourse);
			} else if (order.equals("cancel")) {
				//
			} else
				continue;
			System.out.println("退出请输入exit");
		}
		cin.close();
	}

}
